﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KeMei.Common;

public partial class Manager_Parameters_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserInfo"] == null)
        {
            Response.Redirect(ConfigHelper.SystemUrl + "Manager/login.aspx", true);

        }
        if (!IsPostBack)
        {
            BindList();
        }
    }

    protected void BindList()
    {
        KeMei.BLL.SysParameters bll = new KeMei.BLL.SysParameters();

        try
        {
            Grid1.DataSource = bll.GetModelList("");
            Grid1.DataBind();
        }
        catch (Exception ex)
        {

            ExtAspNet.Alert.Show("绑定列表失败：" + ex.Message);
        }
    }

    protected void Grid1_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
    {

        object[] rowDataKeys = Grid1.DataKeys[e.RowIndex];

        if (e.CommandName == "Edit")
        {
            KeMei.BLL.SysParameters bll = new KeMei.BLL.SysParameters();
            KeMei.Model.SysParameters model = new KeMei.Model.SysParameters();
            try
            {
                model.ID =  Convert.ToInt32(rowDataKeys[0].ToString());
                model.TName = rowDataKeys[1].ToString();
                ExtAspNet.GridRow row = Grid1.Rows[e.RowIndex];
                System.Web.UI.WebControls.TextBox txtValue = (System.Web.UI.WebControls.TextBox)row.FindControl("txtValue");
                model.TValue = txtValue.Text.Trim();
                if (string.IsNullOrEmpty(model.TValue))
                {
                    ExtAspNet.Alert.Show("请填写值");
                    return;
                }
                bll.Update(model);
                ExtAspNet.Alert.Show("修改成功");
               
            }
            catch (Exception ex)
            {
                ExtAspNet.Alert.Show("删除失败：" + ex.Message);
            }
        }
    }
}